
<%@ page import="java.util.List" %>
<%@ page import="cn.NewsDao.NewsDao1" %>
<%@ page import="cn.NewsDaoImpl.NewsDaoImpl1" %>
<%@ page import="cn.entity.News1" %>
<%@ page import="cn.entity.Count" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path =request.getContextPath();
%>
<%
    String path1 =request.getContextPath();
%>
<html>
<head>
    <title>user表</title>
</head>
<body>
<%--js删除--%>
<%--<script type="text/javascript">
    function del(id) {
        var ajz  =  new XMLHttpRequest();
        var url="newsdel?id="+id;


        ajz.open("get",url,true);
        ajz.send();
        ajz.onreadystatechange=callBack;
        function callBack() {
            console.log(ajz)
            if(ajz.readyState==4 && ajz.status==200){
                var txt = ajz.responseText;
                if(txt==1){
                    alert("删除成功");
                    var path=document.getElementById("path").value;
                    window.location.href=path+"/index2.jsp"
                }else {
                    alert("删除失败")
                }
            }
        }
    }
</script>--%>







<script src="js/jquery-1.12.4.min.js"></script>
<script type="text/javascript">

    function login(){
        var name = $("#username").val();
        var pass = $("#passwd").val();
        alert(name)
        $.ajax({
            url:"newsdel?id="+id,
            type:"get",
            data:{
                username:name,
                password:pass
            },
            dataType:"text",

            success:function (data) {
                alert(data)

                if (data==1){
                    var path=document.getElementById("path").value;
                    window.location.href=path+"/index2.jsp"
                }

            },
            error:function () {

                    alert("出现异常")


            }
        })
    }
    function del(id){

        $.ajax({
            url:"delect?id="+id,
            type:"get",
            data:{
                id
            },
            dataType:"text",
            success:function (data) {
                alert(data)

                if (data==1){
                    var path=document.getElementById("path1").value;
                    window.location.href=path+"/index2.jsp"
                }else {
                    alert("删除失败")
                }
            },
            error:function () {

                    alert("出现异常")


            }
        })
    }

</script>













<h1>登录人数<%=Count.count%></h1>
<%
    //NewsService newsService = new NewsServiceImpl();
    NewsDao1 newsDao1 = new NewsDaoImpl1();


    //List<News> newsList= newsService.ServiceSelectAll();
    //初始化分页参数
    int index=0;
    int crenCount=1;
    List<News1> newsList= (List<News1>) session.getAttribute("list");
    Object  index1= session.getAttribute("index1");


    if (index1==null){
        index=1;
    }else {
        index= (int) session.getAttribute("index1");
    }

    if(newsList ==null){
        newsList=newsDao1.getNewsList();

    }

%>
<%
    NewsDao1 newsDao3 = new NewsDaoImpl1();
    List<News1> newsList1 = newsDao3.getNewsList();
%>
    <div>
        <table>
            <%
                for (int i=0;i<newsList1.size();i++) {
            %>
            <tr>
                <td>
                    <%=newsList1.get(i).getId()%>
                </td>
                <td>
                    <%=newsList1.get(i).getCategoryId()%>
                </td>

                <td>
                    <%=newsList1.get(i).getTitle()%>
                </td>
                <td>
                    <%=newsList1.get(i).getSummary()%>
                </td>
                <td>
                    <%=newsList1.get(i).getContent()%>
                </td>

                <td>
                    <%=newsList1.get(i).getAuthor()%>
                </td>
                <td>
                    <%=newsList1.get(i).getCreateDate()%>
                </td>
               <%-- <td ><a href="#" onclick="de(<%=newsList1.get(i).getId()%>)">删除</a></td>--%>
                <td><a href="#" onclick="del(<%=newsList1.get(i).getId()%>)">删除</a></td>
                <td><a href="<%=path%>/system/UpdateManege.jsp?newsid=<%=newsList1.get(i).getId()%>">修改</a></td>
                <td><a href="<%=path%>/system/InsertManege.jsp?newsid=<%=newsList1.get(i).getId()%>">添加</a></td>
                <input type="hidden" id="path" value="<%=path%>">
                <input type="hidden" id="path1" value="<%=path1%>">
    </tr>
    <%
      }
    %>
            <tr>
                <td><a href?index=<%=1%>&crenCount=<%=crenCount%>">首页</a></td>
                <td><a href="/pageManage.jsp?index=<%=(index-1)<0 ? 0:index-1%>&crenCount=<%=crenCount%>">上一页</a></td>
                <td><a href="/pageManage.jsp?index=<%=index+1%>&crenCount=<%=crenCount%>">下一页</a></td>
                <td>当前页：第<%=index%>页</td>
                <td> /</td>
                <td>总页数：<%=newsList.size()%></td>
                <td><a href="pageManage.jsp?index=<%=newsList.size()-1%>&crenCount=<%=crenCount%>">尾页</a></td>
            </tr>

        </table>

</div>
<%
    NewsDao1 newsDao2 = new NewsDaoImpl1();
    List<News1> newsList2 = newsDao2.getNewsList();
    pageContext.setAttribute("newsList2", newsList2);
%>

<div>
    <table border="1" style="border-collapse:collapse;">
        <hr>
        <%--使用forEach循环--%>
        <h1>使用forEach循环</h1>
        <c:set var="bb" value="${newsList2}"></c:set>

        <c:forEach var="news" items="${bb}"  varStatus="status">
            <c:if test="${status.count % 2 !=0}">
                <tr bgcolor="#f158ff">
            </c:if>
            <c:if test="${status.count % 2 ==0}">
                <tr bgcolor="#ff8c00">
            </c:if>
            <td><c:out value="${news.id}"></c:out></td>
            <td><c:out value="${news.categoryId}"></c:out> </td>
            <td><c:out value="${news.title}"></c:out> </td>
            <td><c:out value="${news.summary}"></c:out> </td>
            <td><c:out value="${news.content}"></c:out></td>
            <td><c:out value="${news.author}"></c:out></td>
            <td><fmt:formatDate value="${news.createDate}" pattern="yyyy-MM-dd"></fmt:formatDate></td>
            <br>
            </tr>
        </c:forEach>
    </table>
</div>

<%--<%
    for (int i=0;i<newsList.size();i++) {
%>
    <c:forEach items="${newsList1.get(0).id+newsList1.get(0).categoryId+newsList1.get(0).title + newsList1.get(0).summary + newsList1.get(0).content + newsList1.get(0).author + newsList1.get(0).createDate}" var="n">
        ${n}
    </c:forEach>
<%}%>--%>








</body>
</html>
